package mysql

import (
	"gitee.com/csingo/cDB/drivers"
)

const (
	Driver drivers.DBDriver = "mysql"
)

type Connection struct {
	Driver      drivers.DBDriver       `json:"driver"`
	Host        string                 `json:"host"`
	Port        int                    `json:"port"`
	Database    string                 `json:"database"`
	Username    string                 `json:"username"`
	Password    string                 `json:"password"`
	Charset     string                 `json:"charset"`
	Collation   string                 `json:"collation"`
	Prefix      string                 `json:"prefix"`
	ParseTime   bool                   `json:"parse_time"`
	Location    string                 `json:"location"`
	Debug       bool                   `json:"debug"`
	Pool        *ConnectionPool        `json:"pool"`
	HealthCheck *ConnectionHealthCheck `json:"health_check"`
}

type ConnectionPool struct {
	MaxIdleConnections int `json:"max_idle_connections"`
	MaxConnections     int `json:"max_connections"`
	ConnectTimeout     int `json:"connect_timeout"`
	MaxIdleTime        int `json:"max_idle_time"`
}

type ConnectionHealthCheck struct {
	TableName string `json:"table_name"`
	Key       string `json:"key"`
}

func (i *Connection) GetDriver() drivers.DBDriver {
	return i.Driver
}

func (i *Connection) IsDebug() bool {
	return i.Debug
}

func (i *Connection) NewConnector(name string) (drivers.ConnectorInterface, error) {
	return NewMysqlConnector(name, i)
}
